package com.huchao.www.dao;

import com.huchao.www.pojo.AdminInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.time.LocalDateTime;
import java.time.Period;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @Description:
 * @BelongsProject: springMVC
 * @BelongsPackage: com.huchao.www.mapper
 * @Author: 亖思
 * @CreateTime: 2022/12/4 9:39
 * @Version: 1.0
 */
@Mapper
public interface AdminMapper {

    /**
     * 〈根据登录信息查找admin〉
     *
     * @param loginName:登录名
     * @Author: 亖思
     * @Date: 2022/12/4 9:41
     * @return: UsersInfo
     **/
    @Select("select * from admin_info where login_name = #{loginName} and password = #{password}")
    AdminInfo findByLoginAccount(@Param("loginName") String loginName, @Param("password") String password);

    /**
     * 〈根据id查找〉
     *
     * @param id:id
     * @Author: 亖思
     * @Date: 2022/12/17 20:36
     * @return: AdminInfo
     **/
    @Select("select * from admin_info where admin_id = #{id} ")
    @Results({
            @Result(id = true, property = "adminId", column = "admin_id"),
            @Result(column = "login_name", property = "loginName"),
            @Result(column = "password", property = "password"),
            @Result(column = "phone", property = "phone"),
            @Result(column = "email", property = "email"),
            @Result(column = "profile", property = "profile"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "status", property = "status"),
            @Result(column = "del_status", property = "delStatus"),
            @Result(column = "del_time", property = "delTime")
    })
    AdminInfo findByAdminId(@Param("id") Long id);

    /**
     * 〈根据用户名查询〉
     *
     * @param loginName:
     * @Author: 亖思
     * @Date: 2023/1/13 21:50
     * @return: AdminInfo
     **/
    @Select("select * from admin_info where login_name = #{loginName} and del_status != 1")
    @Results({
            @Result(id = true, property = "adminId", column = "admin_id"),
            @Result(column = "login_name", property = "loginName"),
            @Result(column = "password", property = "password"),
            @Result(column = "phone", property = "phone"),
            @Result(column = "email", property = "email"),
            @Result(column = "profile", property = "profile"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "status", property = "status"),
            @Result(column = "del_status", property = "delStatus"),
            @Result(column = "del_time", property = "delTime")
    })
    AdminInfo findByUserName(@Param("loginName") String loginName);

    /**
     * 〈修改信息〉
     *
     * @param password:密码
     * @param phone:手机
     * @param email:邮箱
     * @Author: 亖思
     * @Date: 2022/12/17 20:56
     * @return: boolean
     **/
    @Update("update admin_info set phone = #{phone},email = #{email},profile = #{profile},password = #{password} where login_name = #{loginName}")
    boolean updateAdmin(@Param("password") String password,
                        @Param("phone") String phone,
                        @Param("email") String email,
                        @Param("profile") String profile,
                        @Param("loginName") String loginName);

    /**
     * 〈查询所有〉
     *
     * @Author: 亖思
     * @Date: 2022/12/6 20:37
     * @return: List<AdminInfo>
     **/
    @Select("select * from admin_info where del_status = 0")
    List<AdminInfo> findAll();

    /**
     * 〈单条软删除〉
     *
     * @param id:id
     * @Author: 亖思
     * @Date: 2022/12/17 21:43
     * @return: boolean
     **/
    @Update("update admin_info set del_status = 1,del_time = #{delTime} where admin_id = #{id}")
    boolean deleteByAdminId(@Param("id") Long id, @Param("delTime") Date delTime);

    /**
     * 〈添加管理员〉
     *
     * @param admin:管理员实体
     * @Author: 亖思
     * @Date: 2022/12/6 20:37
     * @return: boolean
     **/
    @Insert("insert into admin_info(login_name,password,phone,email,profile,create_time) values(#{loginName},#{password},#{phone},#{email},#{profile},#{createTime})")
    boolean saveAdmin(AdminInfo admin);

    /**
     * 〈判断账号是否唯一〉
     *
     * @param loginName:用户名
     * @Author: 亖思
     * @Date: 2022/12/6 21:24
     * @return: String
     **/
    @Select("select login_name from admin_info where login_name = #{loginName} ")
    String isLoginNameRepeat(@Param("loginName") String loginName);

    /**
     * 〈分页查询〉
     *
     * @param map:
     * @Author: 亖思
     * @Date: 2022/12/12 16:47
     * @return: List<AdminInfo>
     **/
    List<AdminInfo> findAdminPageList(HashMap<String, Object> map);
}
